#include "friend_server.hpp"

//日志类参数
DEFINE_bool(log_mod,false,"true为发布模式,false为调试模式");
DEFINE_string(log_file,"","发布模式下日志存储的文件");
DEFINE_int32(log_level,0,"要输出的日志等级");
//服务管理注册类参数
DEFINE_string(registry_host,"http://127.0.0.1:2379","服务注册中心地址");
DEFINE_string(base_service,"/service","服务查询的根目录");

DEFINE_string(user_service,"/service/user_service","服务查询的根目录");
DEFINE_string(message_service,"/service/message_service","服务查询的根目录");


DEFINE_string(instance_name,"/friend_service/instance","当前实例名称"); 
DEFINE_string(access_host,"127.0.0.1:10006","当前实例的访问地址");
//RPC调用类参数
DEFINE_int32(listen_port,10006,"RPC服务监听端口");
DEFINE_int32(rpc_timeout,-1,"RPC调用超时时长");
DEFINE_int32(rpc_threads,1,"RPC调用的IO线程数量");

//数据库参数
DEFINE_string(mysql_host,"127.0.0.1","mysql服务器访问地址");
DEFINE_string(mysql_user,"root","mysql客户端登录账号");
DEFINE_string(mysql_pswd,"123456","mysql客户端登录密码");
DEFINE_string(mysql_db,"TESTDB","mysql默认库名字");
DEFINE_string(mysql_cset,"utf8","mysql客户端的默认编码方式");
DEFINE_int32(mysql_port,0,"mysql服务器访问端口");
DEFINE_int32(mysql_pool_count,4,"mysql连接池的最大链接数量");

DEFINE_string(es_host,"http://127.0.0.1:9200/","ES搜索引擎服务器URL");



int main(int argc,char* argv[])
{
    google::ParseCommandLineFlags(&argc,&argv,true);
    zzy_mims::init_logger(FLAGS_log_mod,FLAGS_log_file,(spdlog::level::level_enum)FLAGS_log_level);
    
    //关闭brpc的默认日志输出
    logging::LoggingSettings logset;
    logset.logging_dest = logging::LoggingDestination::LOG_TO_NONE;
    logging::InitLogging(logset);


    zzy_mims::FriendServerBuilder fsb; 
    fsb.make_mysql_object(FLAGS_mysql_user, FLAGS_mysql_pswd,FLAGS_mysql_db, FLAGS_mysql_host, 
    FLAGS_mysql_cset, FLAGS_mysql_port, FLAGS_mysql_pool_count);
    fsb.make_es_object({FLAGS_es_host});
    fsb.make_discover_object(FLAGS_registry_host, FLAGS_base_service, FLAGS_user_service,FLAGS_message_service);

    fsb.make_rpc_server(FLAGS_listen_port, FLAGS_rpc_timeout, FLAGS_rpc_threads);
    fsb.make_reg_object(FLAGS_registry_host, FLAGS_base_service + FLAGS_instance_name, FLAGS_access_host);
    auto server = fsb.build();
    server->start();
    return 0;
}
